<?php

namespace app\user\controller;

use app\common\respond\HttpApi;
use app\user\logic\FeedMeatRatioLogic;

/**
 * 料肉比控制器
 */
class FeedMeatRatioController
{
    /**
     * @Description 猪栋/猪栏/生猪 料肉比统计
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/27 16:27:33
     * @return \think\response\Json
     */
    public function statistic(HttpApi $respond)
    {
        $param = [
            'barn_id' => request()->get('barn_id'),
            'fence_id' => request()->get('fence_id'),
            'pig_id' => request()->get('pig_id'),
            'record_time_start' => request()->get('record_time_start'),
            'record_time_end' => request()->get('record_time_end'),
        ];
        $rule = [
            'barn_id' => 'integer|>:0',
            'fence_id' => 'integer|>:0',
            'pig_id' => 'integer|>:0',
            'record_time_start' => 'require|dateFormat:Y-m-d H:i:s',
            'record_time_end' => 'require|dateFormat:Y-m-d H:i:s',
        ];
        validate($rule)->check($param);

        $logic = new FeedMeatRatioLogic();
        $data = $logic->statistic($param);

        return $respond->success($data);
    }

    /**
     * @Description 近三天料肉比 比较
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/27 17:08:02
     * @return \think\response\Json
     */
    public function compare(HttpApi $respond)
    {
        $param = [
            'barn_id' => request()->get('barn_id'),
            'fence_id' => request()->get('fence_id'),
            'pig_id' => request()->get('pig_id'),
        ];
        $rule = [
            'barn_id' => 'integer|>:0',
            'fence_id' => 'integer|>:0',
            'pig_id' => 'integer|>:0',
        ];
        validate($rule)->check($param);

        $logic = new FeedMeatRatioLogic();
        $data = $logic->compare($param);

        return $respond->success($data);
    }

}